package com.cindata

import com.cindata.dictionary.*

class ContactImport
{

    ContactImportBatch batch

    String externalId
    String fullName
    String sex
    ContactIdentityType identityType
    String idNumber
    String cellphone
    String address
    String bankAccountNo
    String householdAddress
    String workUnitName
    String position

    String reason

    Date createdDate = new Date()
    Date modifiedDate = new Date()
    User createBy
    User modifyBy

    ExecStatusDict evaluateStatue

    ContactImport()
    {
    }

    ContactImport(ContactImportBatch batch, String externalId, String fullName, String sex,ContactIdentityType identityType,String idNumber,String cellphone,
                  String address,String bankAccountNo,String householdAddress,String workUnitName,String position, Date createdDate, User createBy)
    {
        this.batch = batch
        this.externalId = externalId
        this.fullName = fullName
        this.sex = sex
        this.identityType = identityType
        this.idNumber = idNumber
        this.cellphone = cellphone
        this.address = address
        this.bankAccountNo = bankAccountNo
        this.householdAddress = householdAddress
        this.workUnitName = workUnitName
        this.position = position
        this.createdDate = createdDate
        this.createBy = createBy
    }

    static mapping = {
        autowire true
    }

    static constraints = {
        batch nullable: true, blank: true
        externalId maxSize: 50, nullable: true, blank: true
        fullName maxSize: 20, nullable:true,blank:true
        sex maxSize: 2, nullable: true, blank: true
        sex inList: ['男', '女']
        identityType nullable: true, blank: true
        idNumber maxSize: 18, nullable:true,blank:true
        cellphone maxSize: 11, nullable: true, blank: true
        address maxSize: 150, nullable: true, blank: true
        bankAccountNo maxSize: 50, nullable: true, blank: true
        householdAddress maxSize: 150, nullable: true, blank: true
        workUnitName maxSize: 50, nullable: true, blank: true
        position maxSize: 50, nullable: true, blank: true


        createdDate nullable: true, blank: true
        modifiedDate nullable: true, blank: true
        createBy nullable: true, blank: true
        modifyBy nullable: true, blank: true

        evaluateStatue nullable: true, blank: true
        reason nullable: true, blank: true

    }

    def afterUpdate()
    {
        this.updateMatchNum()
    }

    // 验证成功，进入押品表,关联关系不明确，暂时不需要进入押品表
    def validSuccess()
    {
//        def contact = new Contact()
//        contact.fullName = this.fullName
//        contact.sex = this.sex
//        contact.identityType = this.identityType
//        contact.idNumber = this.idNumber
//        contact.cellphone = this.cellphone
//        contact.address = this.address
//        //contact.bankAccountNo = this.bankAccountNo
//        contact.householdAddress = this.householdAddress
//        contact.workUnitName = this.workUnitName
//        contact.position = this.position
//        contact.save()
    }

    /*
    * 验证失败
     */

    def validFailure()
    {
    }

    // 更新匹配记录数量
    def updateMatchNum()
    {
        this.batch.updateCount()
    }

}
